package com.coolapk.service.impl;

import com.coolapk.entity.Favorite;
import com.coolapk.entity.FavoriteExample;
import com.coolapk.mapper.FavoriteMapper;
import com.coolapk.service.FavoriteService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FavoriteServiceImpl implements FavoriteService {
    @Resource
    FavoriteMapper favoriteMapper;

    @Override
    public Integer saveFavorite(Favorite favorite) {
        return favoriteMapper.insert(favorite);
    }

    @Override
    public List<Favorite> selectFavoriteList(Integer userId) {
        FavoriteExample favoriteExample = new FavoriteExample();
        FavoriteExample.Criteria criteria = favoriteExample.createCriteria();
        criteria.andUserIdEqualTo(userId);
        favoriteExample.setOrderByClause("`id` DESC");
        return favoriteMapper.selectByExample(favoriteExample);
    }

    @Override
    public Integer deleteFavorite(Integer id) {
        return favoriteMapper.deleteByPrimaryKey(id);
    }
}
